<?php

namespace App\Winged\Tenants ;

use Illuminate\Foundation\Application;

class TenantReader {

    protected $app ;

    public static $instance ;

    public function __construct( Application $app)
    {
        $this->app = $app ;
    }


    public function read( $driver )
    {
        $driver = ucfirst( $driver ) ;

        $class = "\\App\\Winged\\Tenants\\Tenant{$driver}" ;

        if(! class_exists($class)) {
            throw new \RuntimeException( $class . "::not found" ) ;
        }
        return new $class( $this->app ) ;
    }


    public static function getInstance($app)
    {
        if(is_null(self::$instance)){
            self::$instance = new static($app);
        }
        return self::$instance ;
    }
}